import { defineStore } from 'pinia'
import { ref } from 'vue'
import { ElNotification } from 'element-plus'

export const useWorkerStore = defineStore(
  'woker',
  () => {
    const workerList = ref([
      {
        id: 1,
        name: '关智敏',
        age: '17',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 2,
        name: '虞子安',
        age: '24',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 3,
        name: '艾志勇',
        age: '27',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 4,
        name: '蔺冰冰',
        age: '41',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 5,
        name: '易哲',
        age: '18',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 6,
        name: '强瑜',
        age: '35',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 7,
        name: '应正诚',
        age: '23',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 8,
        name: '孟鹏',
        age: '32',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 9,
        name: '陈建军',
        age: '22',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 10,
        name: '席正豪',
        age: '35',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 11,
        name: '黎坤',
        age: '50',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 12,
        name: '苟晧',
        age: '22',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 13,
        name: '沿阳',
        age: '26',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 14,
        name: '柯玉',
        age: '25',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 15,
        name: '齐华',
        age: '19',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 16,
        name: '左利',
        age: '30',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 17,
        name: '文春梅',
        age: '40',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 18,
        name: '虞洁',
        age: '22',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 19,
        name: '位楼',
        age: '50',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 20,
        name: '柯翼',
        age: '21',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 21,
        name: '台玉梅',
        age: '34',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 22,
        name: '曹智渊',
        age: '23',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 23,
        name: '关红霞',
        age: '16',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 24,
        name: '鲁丹丹',
        age: '48',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 25,
        name: '谌艳',
        age: '22',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 26,
        name: '苟淑珍',
        age: '22',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 27,
        name: '郜志明',
        age: '43',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 28,
        name: '鞠斌',
        age: '35',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 29,
        name: '史慧',
        age: '45',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 30,
        name: '原俊',
        age: '27',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 31,
        name: '姬建明',
        age: '49',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 32,
        name: '芦玉珍',
        age: '29',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 33,
        name: '庄辉',
        age: '26',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 34,
        name: '卓飞',
        age: '35',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 35,
        name: '楚亮',
        age: '47',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 36,
        name: '臧冰冰',
        age: '30',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 37,
        name: '党峰',
        age: '31',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 38,
        name: '董丽华',
        age: '40',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 39,
        name: '万涛',
        age: '46',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 40,
        name: '宇桂兰',
        age: '38',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 41,
        name: '鲁洋',
        age: '46',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 42,
        name: '陈志明',
        age: '28',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 43,
        name: '蔡强',
        age: '28',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 44,
        name: '向欢',
        age: '22',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 45,
        name: '仇洪',
        age: '22',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 46,
        name: '秦瑶',
        age: '47',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 47,
        name: '汪玉梅',
        age: '22',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 48,
        name: '郎建平',
        age: '44',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 49,
        name: '万瑜',
        age: '33',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 50,
        name: '齐敏',
        age: '35',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 51,
        name: '匡萍',
        age: '29',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 52,
        name: '韦志强',
        age: '24',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 53,
        name: '汤玉',
        age: '40',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 54,
        name: '隋欣',
        age: '19',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 55,
        name: '车宇',
        age: '27',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 56,
        name: '卢哲彦',
        age: '27',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 57,
        name: '岳红梅',
        age: '36',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 58,
        name: '靳春梅',
        age: '16',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 59,
        name: '尹坤',
        age: '47',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 60,
        name: '官秀兰',
        age: '49',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 61,
        name: '卢新华',
        age: '22',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 62,
        name: '荆桂香',
        age: '28',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 63,
        name: '明涛',
        age: '31',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 64,
        name: '卓馨予',
        age: '23',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 65,
        name: '燕秀兰',
        age: '21',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 66,
        name: '严欢',
        age: '31',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 67,
        name: '卓亮',
        age: '27',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 68,
        name: '车建军',
        age: '31',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 69,
        name: '汤楠',
        age: '16',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 70,
        name: '张瑞',
        age: '41',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 71,
        name: '韩雪梅',
        age: '40',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 72,
        name: '邓玉兰',
        age: '35',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 73,
        name: '谌楠',
        age: '33',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 74,
        name: '何春梅',
        age: '42',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 75,
        name: '黄华',
        age: '31',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 76,
        name: '田桂花',
        age: '33',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 77,
        name: '成亮',
        age: '43',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 78,
        name: '颜倩',
        age: '46',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 79,
        name: '唐冰冰',
        age: '23',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 80,
        name: '卓帅',
        age: '22',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 81,
        name: '姜凤兰',
        age: '44',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 82,
        name: '田珺',
        age: '18',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 83,
        name: '王桂珍',
        age: '40',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 84,
        name: '汤正平',
        age: '21',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 85,
        name: '温峰',
        age: '29',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 86,
        name: '臧腊梅',
        age: '43',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 87,
        name: '林静',
        age: '34',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 88,
        name: '徐松',
        age: '23',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 89,
        name: '吕春梅',
        age: '45',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 90,
        name: '郝洋',
        age: '40',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 91,
        name: '孔浩',
        age: '25',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 92,
        name: '喻志明',
        age: '50',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 93,
        name: '阮磊',
        age: '20',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 94,
        name: '谷玉珍',
        age: '39',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 95,
        name: '汤瑞',
        age: '41',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 96,
        name: '申欣',
        age: '34',
        gender: '1',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 97,
        name: '祝晨',
        age: '47',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 98,
        name: '彭华',
        age: '16',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 99,
        name: '汤新华',
        age: '18',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      },
      {
        id: 100,
        name: '吉丽丽',
        age: '18',
        gender: '0',

        created_at: '2024-06-12T06:10:38.000000Z',
        updated_at: '2024-06-12T06:10:38.000000Z'
      }
    ])

    const workerData = ref([])

    const loading = ref(true)
    const getWorkData = async (page, pageSize) => {
      ElNotification.closeAll()
      loading.value = true
      workerData.value = await new Promise((r) =>
        setTimeout(
          () =>
            r(workerList.value.slice((page - 1) * pageSize, page * pageSize)),
          300
        )
      )
      ElNotification({
        title: '获取成功',
        type: 'success'
      })
      loading.value = false
    }

    const delData = (data) => {
      if (Array.isArray(data)) {
        data.forEach((i) => {
          workerList.value.splice(
            workerList.value.findIndex((s) => s.id == i.id),
            1
          )
        })
      } else if (data == 'all') workerList.value = []
      else {
        workerList.value.splice(
          workerList.value.findIndex((i) => i.id == data.id),
          1
        )
      }
    }

    const addWorker = (data) => {
      workerList.value.push(data)
      ElNotification({
        title: '添加成功',
        type: 'success'
      })
    }

    const editWorker = (data) => {
      workerList.value[workerList.value.findIndex((i) => i.id == data.id)] =
        data
      ElNotification({
        title: '编辑成功',
        type: 'success'
      })
    }

    return {
      editWorker,
      workerList,
      workerData,
      getWorkData,
      loading,
      delData,
      addWorker
    }
  },
  {
    persist: true
  }
)
